package com.ruoyi.project.module.itemDetail.service;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.module.itemDetail.mapper.ItemDetailMapper;
import com.ruoyi.project.module.itemDetail.domain.ItemDetail;
import com.ruoyi.project.module.itemDetail.service.IItemDetailService;
import com.ruoyi.common.support.Convert;

/**
 * 商品库存 服务层实现
 * 
 * @author ruoyi
 * @date 2018-08-08
 */
@Service
public class ItemDetailServiceImpl implements IItemDetailService 
{
	@Autowired
	private ItemDetailMapper itemDetailMapper;

	/**
     * 查询商品库存信息
     * 
     * @param itemDetailId 商品库存ID
     * @return 商品库存信息
     */
    @Override
	public ItemDetail selectItemDetailById(Integer itemDetailId)
	{
	    return itemDetailMapper.selectItemDetailById(itemDetailId);
	}
	
	/**
     * 查询商品库存列表
     * 
     * @param itemDetail 商品库存信息
     * @return 商品库存集合
     */
	@Override
	public List<ItemDetail> selectItemDetailList(ItemDetail itemDetail)
	{
	    return itemDetailMapper.selectItemDetailList(itemDetail);
	}
	
    /**
     * 新增商品库存
     * 
     * @param itemDetail 商品库存信息
     * @return 结果
     */
	@Override
	public int insertItemDetail(ItemDetail itemDetail)
	{
	    return itemDetailMapper.insertItemDetail(itemDetail);
	}
	
	/**
     * 修改商品库存
     * 
     * @param itemDetail 商品库存信息
     * @return 结果
     */
	@Override
	public int updateItemDetail(ItemDetail itemDetail)
	{
	    return itemDetailMapper.updateItemDetail(itemDetail);
	}

	/**
     * 删除商品库存对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteItemDetailByIds(String ids)
	{
		return itemDetailMapper.deleteItemDetailByIds(Convert.toStrArray(ids));
	}

	/**
	 * @Author lcx
	 * @Date 2018/8/8 21:04
	 * 插入爬取到的商品信息详细信息
	 */
	@Override
	public int insertItemDetailAsCrawlItemDetail(List list, int itemDetailCount) {

		for (ItemDetail itemDetail: (List<ItemDetail>) list){
			itemDetail.setItemDetailCount(itemDetailCount);
			System.out.println(itemDetail.toString());
			itemDetailMapper.insertItemDetail(itemDetail);
		}
		return 0;
	}

	/**
	 *  @Author lcx
	 * @Date 2018/8/12 16:04
	 */
	@Override
	public int findMaxItemDetailInventory() {
		return itemDetailMapper.selectItemDetailAsMaxItemDetailInventory();
	}

}
